﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cloud.Model;
using Cloud.BLL;
public partial class Three_Managerment_Problem_save_Edit1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["users"] == null)
        {
            Response.Write("<script>alert('1'); window.parent.location.href='/index.html'</script>");

        }
        if (IsPostBack)
        {

        }
        else
        {
            int id = Convert.ToInt32(Request.QueryString["id"]);
            Problem activity = ProblemManager.FindById(id);
            if (activity != null)
            {
                if (activity.Satisfied.Equals("0"))
                {
                    this.xm.Value = activity.Appeal_name.ToString();
                    this.lxfs.Value = activity.Appeal_tel;
                }
                else
                {
                    this.xm.Value = activity.Appeal_name.ToString();
                    this.lxfs.Value = activity.Appeal_tel;
                }
                this.lab_xbsj.InnerText = activity.Xbtime == new DateTime(1900, 01, 01, 00, 00, 00) ? "无限办时间" : activity.Xbtime.ToString();

                this.sjbh.Value = activity.Appealid.ToString();
                this.sbsj.Value = activity.Regtime.ToString();
                this.gs.Value = AscriptionManager.FindById(activity.Ascription_id).Name;
                this.dl.Value = Classification_Appeal1Manager.FindById(activity.Appeal_type_id).Name;
                this.xl.Value = Classification_Appeal2Manager.FindById(activity.Xialei).Name;
                this.yx.Value = activity.Appeal_email;
                this.bt.Value = activity.Title;
                this.nr.Value = activity.Context;
                this.gh.Value = activity.Jobnum.ToString();
                if (activity.Current_ld == 0)
                {
                    dbm.Value = "一级部门办理中";
                }
                else if (activity.Current_ld == 1)
                {
                    dbm.Value = "二级部门办理中";
                }
                else if (activity.Current_ld == 2)
                {
                    dbm.Value = "三级部门办理中";
                }
                this.repeater.DataSource = Problem_historic2Manager.FindBysj(activity.Appealid);
                this.repeater.DataBind();
                this.div.Visible = false;
            }
        }
    }

    public String dwxx(String id)
    {
        try
        {
            String res = "";
            if (id.Length == 6)
            {
                if (DWManager.FindById(id) == null)
                {
                    res = ZS_TYPEINFOManager.FindById(id).NAME;
                }
                else
                {

                    res = DWManager.FindById(id).DWMC;
                }
            }
            else if (id.Length == 3 || id.Length == 2 || id.Length == 1)
            {
                if (ZS_TYPEINFOManager.FindById(id) != null)
                {
                    res = ZS_TYPEINFOManager.FindById(id).NAME;
                }
                else
                {
                    res = DWManager.FindById(id).DWMC;
                }

            }
            else
            {
                res = "121311313";
            }
            return res;
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('1234'); window.parent.location.href='/index.html'</script>");
            return "";
        }
    }
    public String sjlx(int id)
    {
        String res = "";
        try
        {

            if (id == 0)
            {
                res = "受理";
            }
            else if (id == 1)
            {
                res = "派遣";
            }
            else if (id == 2)
            {
                res = "直办";
            }
            else if (id == 3)
            {
                res = "反馈";
            }
            else if (id == 4)
            {
                res = "审核";
            }
            else if (id == 5)
            {
                res = "驳回";
            }
            else if (id == 6)
            {
                res = "督办";
            }
            else if (id == 7)
            {
                res = "延期";
            }
            else if (id == 8)
            {
                res = "办结";
            }
            else if (id == 9)
            {
                res = "申请办结";
            }

        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('144'); window.parent.location.href='/index.html'</script>");
            return "";
        }
        return res;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            int id = Convert.ToInt32(Request.QueryString["id"]);
            Problem activity = ProblemManager.FindById(id);
            if (activity != null)
            {
                activity.Appealid = this.sjbh.Value;
                activity.Regtime = Convert.ToDateTime(this.sbsj.Value);
                activity.Appeal_name = this.xm.Value;
                activity.Appeal_tel = this.lxfs.Value;
                activity.Ascription_id = AscriptionManager.FindByName(this.gs.Value).Id;
                activity.Appeal_type_id = Classification_Appeal1Manager.FindByName(this.dl.Value).Id;
                activity.Xialei = Classification_Appeal2Manager.FindByName(this.xl.Value).Id;
                activity.Appeal_email = this.yx.Value;
                activity.Title = this.bt.Value;
                activity.Context = this.nr.Value;
                activity.Jobnum = Convert.ToInt32(this.gh.Value);

                if (dbm.Value == "一级部门办理中")
                { activity.Current_ld = 0; }
                else if (dbm.Value == "二级部门办理中")
                { activity.Current_ld = 1; }
                else if (dbm.Value == "三级部门办理中")
                { activity.Current_ld = 2; }
                ProblemManager.Update(activity);
                Response.Write("<script>alert('保存成功！');</script>");
            }

        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('" + ex.Message + "'); window.parent.location.href=location.href;</script>");
            return;
        }

    }

    protected void repeater_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        try
        {
            if (Session["users"] == null)
            {
                Response.Write("<script>alert('1111111！');window.parent.parent.location.href='/Login.aspx'</script>");
            }
            else
            {
                this.div.Visible = true;
                if (e.CommandName.Equals("links"))
                {
                    Problem_historic2 his2 = Problem_historic2Manager.FindById(Convert.ToInt32(e.CommandArgument));
                    this.lab_title.InnerHtml = his2.Title;
                    this.lab_slr.InnerHtml = his2.Name;
                    this.lab_hf.InnerHtml = his2.Blyj;
                }
            }
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('99999976666'); window.parent.location.href='/index.html'</script>");
            return;
        }

    }
}